﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bussiness;

namespace WebApplication.Admin
{
    public partial class TonVoList : System.Web.UI.Page
    {
        CHUCNANG objchucnang = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadHienthi();
            }

        }
        public void LoadHienthi()
        {
            IUnitOfWork iunitfwork = new EFUnitOfWork();
            TONKHO_VORepository repository = new TONKHO_VORepository(new EFRepository<TONKHO_VO>(), iunitfwork);
            IQueryable<TONKHO_VO> objtonkhovo = repository.All();
            Grtonvo.DataSource = objtonkhovo;
            Grtonvo.DataBind();
        }

        protected void Grtonvo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex < 0) return;
            TONKHO_VO objtonkhovo = ((TONKHO_VO)e.Row.DataItem);
            if (objtonkhovo != null)
            {
                Label lbmathang = ((Label)e.Row.FindControl("lbmathang"));
                Label lbtinhtrang = ((Label)e.Row.FindControl("lbtinhtrang"));
                if (!string.IsNullOrEmpty(objtonkhovo.MAMH))
                {
                    lbmathang.Text = objtonkhovo.MATHANG.TENMH;
                }
                if (objtonkhovo.TINHTRANG == true)
                {
                    lbtinhtrang.Text = "Có lấy vỏ";
                }
                else
                {
                    lbtinhtrang.Text = "Không lấy vỏ";
                }
            }
        }
       
        protected void Grtonvo_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            LoadHienthi();
            Grtonvo.PageIndex = e.NewSelectedIndex;
            Grtonvo.DataBind();
        }
    }
}